//
//  UIManage.m
//  expend
//
//  Created by ZAK on 14-3-27.
//  Copyright (c) 2014年 JKZL. All rights reserved.
//

#import "UIManage.h"

@implementation UIManage
+(UIButton *)createButtonFrame:(CGRect)rect withBackColor:(UIColor *)bgColor BackgroundImage:(UIImage *)image lightImageView:(UIImage *)lightImage withTarget:(id)target withAction:(SEL)action withTitle:(NSString *)title withtextfont:(UIFont *)font withTextColor:(UIColor *)color
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (image == nil) {
//        button.layer.cornerRadius = 5.0f;
    }
    if (bgColor) {
        [button setBackgroundColor:bgColor];
    }
    button.frame = rect;
    if (image != nil) {
        [button setBackgroundImage:image forState:UIControlStateNormal];
    }
    if (lightImage != nil) {
        [button setBackgroundImage:lightImage forState:UIControlStateSelected];
    }
    if (target && action) {
        [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    if (title != nil) {
        [button setTitle:title forState:UIControlStateNormal];
    }
    if (font) {
        button.titleLabel.font = font;
    }
    if (color) {
        [button setTitleColor:color forState:UIControlStateNormal];
    }
    return button ;
}
+(UIButton *)createButtonFrame:(CGRect)rect withBackColor:(UIColor *)bgColor BackgroundImage:(UIImage *)image lightImageView:(UIImage *)lightImage withTarget:(id)target withAction:(SEL)action withAttributedTitle:(NSMutableAttributedString *)title withtextfont:(UIFont *)font withTextColor:(UIColor *)color
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (image == nil) {
        //        button.layer.cornerRadius = 5.0f;
    }
    if (bgColor) {
        [button setBackgroundColor:bgColor];
    }
    button.frame = rect;
    if (image != nil) {
        [button setBackgroundImage:image forState:UIControlStateNormal];
    }
    if (lightImage != nil) {
        [button setBackgroundImage:lightImage forState:UIControlStateSelected];
    }
    if (target && action) {
        [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    if (title != nil) {
        [button setAttributedTitle:title forState:UIControlStateNormal];
    }
    if (font) {
        button.titleLabel.font = font;
    }
    if (color) {
        [button setTitleColor:color forState:UIControlStateNormal];
    }
    return button ;
}

+(UILabel *)createUILabelFrame:(CGRect)rect
                 withBackColor:(UIColor *)bgColor
                 withTextColor:(UIColor *)textColor
                  withTextFont:(UIFont *)font
             withTextAlignment:(NSTextAlignment)alignment
               withTextContent:(NSString *)content
{
    UILabel *label = [[UILabel alloc]initWithFrame:rect];
    if (bgColor) {
        label.backgroundColor = bgColor;
    }else
    {
        label.backgroundColor = [UIColor clearColor];
    }
    if (textColor) {
        label.textColor = textColor;
    }
    if (font) {
        label.font = font;
    }
    if (alignment) {
        label.textAlignment = alignment;
    }
    if (content != nil ) {
        if ([content isKindOfClass:[NSString class]]) {
            label.text = content;
        }
    }else
    {
        label.text = @"";
    }
    return label ;
}

+(UITextField *)createUITextFieldFrame:(CGRect)rect
                          delegate:(id)target
                              text:(NSString *)content
                         placeholder:(NSString *)placeholder
                          withborStyle:(UITextBorderStyle)style
                         returnKey:(UIReturnKeyType)keyTyle
                          keyBoard:(UIKeyboardType)keyBoard
                          textFont:(UIFont *)font
                         textColor:(UIColor *)color
                     textAlignment:(NSTextAlignment)alignment
                  cleanButtonModel:(UITextFieldViewMode)cleanMode
{
    UITextField *textField = [[UITextField alloc]initWithFrame:rect];
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    
    if (target != nil) {
        textField.delegate = target;
    }
    if (content != nil) {
        textField.text = content;
    }
    if (placeholder !=nil) {
        textField.placeholder = placeholder;
    }
    if (font) {
        textField.font = font;
    }
    if (color) {
        textField.textColor = color;
    }
    
    textField.clearButtonMode =  cleanMode;
    textField.textAlignment = alignment;
    textField.borderStyle = style;
    textField.returnKeyType = keyTyle;
    textField.keyboardType = keyBoard;
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    return textField ;
}

+(UITableView *)createUITableViewFrame:(CGRect)rect TableViewdeletedelete:(id)target type:(UITableViewStyle)style allowsSelection:(BOOL)isAllow separatorStyle:(UITableViewCellSeparatorStyle) separatorStyle separatorColor:(UIColor *)color backgroundColor:(UIColor *)backgroundColor backgroundView:(UIView *)backgroundView
{
    UITableView *tableView = [[UITableView alloc]initWithFrame:rect style:style];
    tableView.delegate = target;
    tableView.dataSource = target;
    if (color) {
        tableView.separatorColor = color;
    }
    tableView.separatorStyle = separatorStyle;
    tableView.allowsSelection = isAllow;
    if (backgroundView) {
        tableView.backgroundView = backgroundView;
    }
    
    if (backgroundColor) {
        tableView.backgroundColor = backgroundColor;
    }
    return tableView ;
}

@end
